from sqlalchemy import (Column, ForeignKey, INTEGER,
                        CHAR, NCHAR, BIGINT, SMALLINT, TIMESTAMP)
from utils.db import Base
from utils.funcs import get_current_date
from utils.regions import DEFAULT_REGION_ID

DEFAULT_USER_CASH = 1000
MAX_LEN_NAME = 64


class User(Base):
    __tablename__ = "user"

    id = Column(INTEGER, primary_key=True, autoincrement=True)
    name = Column(NCHAR(MAX_LEN_NAME), default="Новый игрок", nullable=False)
    email = Column(CHAR(256), nullable=False, unique=True)
    password = Column(CHAR(64), nullable=False)
    time_create = Column(TIMESTAMP, default=get_current_date, nullable=False)
    residence = Column(INTEGER,
                       ForeignKey("region.id", use_alter=True),
                       default=DEFAULT_REGION_ID, nullable=False)
    cash = Column(BIGINT, default=DEFAULT_USER_CASH, nullable=False)
    work_end = Column(TIMESTAMP, default=get_current_date, nullable=False)
    strength = Column(SMALLINT, default=1, nullable=False)
    education = Column(SMALLINT, default=1, nullable=False)
